package com.iotechn.unimall.admin.api.dashboard;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.iotechn.unimall.core.exception.ServiceException;
import com.iotechn.unimall.data.domain.PlantCarPassportDO;
import com.iotechn.unimall.data.dto.AdminDTO;
import com.iotechn.unimall.data.dto.DashboardIntegralDTO;
import com.iotechn.unimall.data.mapper.PlantCarPassportMapper;
import com.iotechn.unimall.data.mapper.UserShopMapper;
import com.iotechn.unimall.data.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by rize on 2019/7/15.
 */
@Service
public class DashboardServiceImpl implements DashboardService {
    @Autowired
    private PlantCarPassportMapper plantCarPassportMapper;
    @Autowired
    private UserShopMapper userShopMapper;

    @Override
    public Object integral(Long adminId) throws ServiceException {
        DashboardIntegralDTO dto = new DashboardIntegralDTO();
        AdminDTO adminDTO = SessionUtil.getAdmin();
        EntityWrapper entityWrapper = new EntityWrapper<PlantCarPassportDO>();
        if (adminDTO.getRoleIds().get(0).intValue() == 1) {
            List<Long> status = new ArrayList<Long>();
            status.add(0L);
            status.add(1L);
            entityWrapper.in("status", status);
        } else {
            List<Long> status = new ArrayList<Long>();
            status.add(0L);
            status.add(1L);
         }
        Integer allCount = userShopMapper.selectCount(entityWrapper);
        EntityWrapper entityWrapper1 = new EntityWrapper<PlantCarPassportDO>();
        List<Long> status = new ArrayList<Long>();
        entityWrapper1.in("status", status);
        if (adminDTO.getRoleIds().get(0).intValue() == 1) {
            status.add(0L);
            entityWrapper1.in("status", status);
        } else {
            status.add(0L);
            entityWrapper1.in("status", status);
         }
        Integer applyCount = userShopMapper.selectCount(entityWrapper1);
        dto.setAllCount(allCount);
        dto.setApplyCount(applyCount);
        return dto;
    }
}
